import java.net.*;
import java.io.*;
import java.util.*;

public class VoiceConnectionHandler implements Runnable
{
	DatagramSocket socket;
	
	public VoiceConnectionHandler(DatagramSocket sock)//The constructor copies the socket into the handler
	{
		socket = sock;
	}
	
	public void run()//The run method handles all the packets being sent by the client and sending to the other client
	{
		byte[] rData = new byte[1024];
		byte[] sData = new byte[1024];
		
		while(true)
		{
			try
			{
				System.out.println("Receiving packet...");
				DatagramPacket rPack = new DatagramPacket(rData, rData.length);
				socket.receive(rPack);
				String input = new String(rPack.getData());
				System.out.println("Packet recieved!");
				
				InetAddress ip = rPack.getAddress();
				int port = rPack.getPort();
				System.out.println("Data: " + input);
				System.out.println("IP: " + ip.toString() + " and port#: " + port);
				/*DatagramPacket sPack = new DatagramPacket(sData, sData.length, ip, port);
				servSock.send(sPack);*/
			}
			catch(IOException e)
			{
				System.err.println(e.getMessage());
				System.exit(1);
			}
		}
	}
}